//
//  StorageCenter.swift
//  Center_Storage
//
//  Created by Flutter on 2021/7/12.
//

import Foundation
import Standard
import Storage

public enum StorageCenter {}

extension StorageCenter: TypeName {}

private extension StorageCenter {
    static let rootURL: URL = {
        do {
            let documentURL = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
            let rootURL = documentURL.appendingPathComponent(typeName)
            return rootURL
        } catch { fatalError("\(error)") }
    }()
}

public extension StorageCenter {
    static let coke: StoreContainer = {
        do {
            let pathURL = rootURL.appendingPathComponent("coke")
            if !FileManager.default.fileExists(atPath: pathURL.path) {
                try FileManager.default.createDirectory(at: pathURL, withIntermediateDirectories: true)
            }
            return try StoreContainer(path: pathURL.path)
        } catch {
            fatalError("\(error)")
        }
    }()
}
